<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php 
	$ci = & get_instance();
	$tid = intval($_GET['tid']);
	$mid = intval($_GET['mid']);
	$TOURNAMENT = $ci->tournament_entity->init("id", $tid);
	$MATCH = $ci->match_entity->init('id',$mid);
	
	if(mCrypt($tid.$mid) != $_GET['scrid']){
		redirect(site_url());exit();
	}	 
	if($MATCH->getStatus() == 'closed' || $MATCH->getStatus() == 'cancelled'){
		redirect(site_url('cricket/tournament/match_closed_notify'));exit();
	}
	echo php2js();
	
	 
?>


<div class="clrboth"></div>	

<div id="center_content">
	<div id="async_event_in_match">
	<!--
		<div class="clrboth"></div>
		<?php //$this->load->view('cricket/cricket/countdown_timeend_of_tournament'); ?>
		<div class="clrboth"></div>	

		<div class="sepDIV"></div>
	-->
		<div class="clrboth"></div>
		<?php $this->load->view('cricket/cricket/countdown_timeend_of_upcoming_match'); ?>
		<div class="clrboth"></div>	

		<div class="sepDIV"></div>

		<div class="clrboth"></div>
		<?php $this->load->view('cricket/cricket/team_in_play_of_match'); ?>
		<div class="clrboth"></div>	

		<div class="sepDIV"></div>

		<div class="clrboth"></div>
		<?php $this->load->view('cricket/cricket/upcoming_matches_of_tournament2'); ?>
		<div class="clrboth"></div>	

		<div class="sepDIV"></div>

		<div class="clrboth"></div>
		<?php $this->load->view('cricket/cricket/closed_matches_of_tournament'); ?>
		<div class="clrboth"></div>	

	</div>
</div>

<script type="text/javascript">
	var event_ID = [];
	var opening_event = {};
	var manual_bet = {};
	google.setOnLoadCallback(function() {
		$('#sys_plugin_my_profile').removeClass('hidden');
		$('#sys_plugin_bet').removeClass('hidden');
		$('#sys_plugin_convertion').removeClass('hidden');
		
		$('#async_event_in_match .clickbet').each(function(i,o){
				var event_id = $(this).attr('rel');
				var p= new PHP_JS();
				p.array_push(event_ID,event_id);
			}
		);		
		setInterval("loadEventInMatch()",20000);
	});
	
	function loadEventInMatch(){
		$opening_event_id = opening_event.id;
		if($opening_event_id){
			return ;
			opening_event.html = $('#direct_bet_'+opening_event.id).html();
		}
		
		$.get(BASE_URI+MODULE+'/contentload/loadEventInUpcomingMatch', {tid:__GET.tid, mid:__GET.mid, scrid:__GET.scrid}, function(res){
			$("#async_event_in_match").html(res);
			/**
			$('.countdown').each(function(i,o){
				var id = $(this).attr('id');
				var time = $(this).attr('rel');
				eval( "sys_time."+id+"="+time);
			});
			**/
			
			$.getScript( BASE_URI +MODULE+ '/contentload/loadConvertionData/?mid='+__GET.mid , function(data, textStatus){
				$('#rate_status').html( sysconvertion.point+':'+sysconvertion.coin);
			});
			
			$opening_event_id = opening_event.id;
			if($opening_event_id != 0){
				$('#direct_bet_'+$opening_event_id).removeClass('hidden');
				$('#direct_bet_'+$opening_event_id).html(opening_event.html);
				$('#direct_stake_'+$opening_event_id).calculateWinPointsGet_direct($opening_event_id,$('#direct_stake_'+$opening_event_id).attr('value'));
			}
			
			restoreManualBetValue();
			
			$('#async_event_in_match .clickbet').each(function(i,o){
				var event_id = $(this).attr('rel');
				var odds = $('#async_event_in_match .clickbet .event_id_'+event_id).text();
				var odds_bet = $('#sys_plugin_bet .event_id_'+event_id).text();
				if(odds_bet){
					$P = new PHP_JS();
					$s = $P.floatval(odds);
					$s2 = $P.floatval(odds_bet);
					
					if($s2 != $s){
						$('#sys_plugin_bet .event_id_'+event_id).text(odds).addClass('brown');
						var rel = $('#sys_plugin_bet .event_id_'+event_id).attr('rel'); 
						$('#event_'+rel).attr('rel',$s);	
						$('#stake_'+rel).calculateWinPointsGet(rel,$('#stake_'+rel).attr('value'));
					}
				}
				
				var p = new PHP_JS();
				if(! p.in_array(event_id,event_ID)){
					//$('.event_'+event_id).append('<div class="update_notice">Added to Bet Slip</div>');
					p.array_push(event_ID,event_id);
				}
				//setInterval(function(){$('.update_notice').remove();},8000); 
			});
			
		});
	}
</script>